home *** CD-ROM | disk | FTP | other *** search
/ El Mac 9 / El Mac 9.iso / Shareware / Applications / MathPad 2.4 / XFuns / XFun kit / util src / callbackg.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-01  |  7.4 KB  |  196 lines  |  [TEXT/CWIE]

  1. /*
  2.  Prototypes for MathPad's callback routines.
  3.  
  4.  This header file is for XFuns that use A4 globals (or for CFuns).
  5.  The file "callbackg.c" implements these routines by using a
  6.  global funptr "callback" which must be set on initialzation.
  7.  
  8.  The compiler must be set so that type "double" is a SANE 80-bit.
  9.  
  10. */
  11.  
  12. typedef short (*funptr) ();
  13. typedef struct expr    *EXPR;    /* internal details aren't needed by XFun */
  14.  
  15. extern funptr callback;
  16.  
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20.  
  21. /* ---------- control routines ---------------------------- */
  22.  
  23. extern void AddXfun(char *name,char *parms,funptr entry,funptr predef);
  24.   /* Install a new function from a code resource. */
  25.   //(internally defined a static)
  26.   
  27. extern void AddFunDim(char *name, long lim);
  28.   /* Setup routine to allow the XFun to return values based on the array index.
  29.    This routine must be called by the predef routine. It can be called multiple times
  30.    to set up a multidimensional return value. Array index values are appended to the
  31.    parameter list */
  32.  
  33. extern void ErrMsg(char *fmt,char *str);
  34.   /* Show an error message in the status line.
  35.     fmt is a printf() format string. str is an optional parameter
  36.     Sets stop flag to tell MathPad to stop all evaluation. */
  37.  
  38. extern short Stopped(void);
  39.   /* Check value of stop flag to see if evaluation should be stopped. */
  40.  
  41. extern void SpinWatch(void);
  42.   /* Allow a computation to be switched to background or stopped via command period.
  43.    Stopped() must be checked to see if command period was hit.
  44.    SpinWatch() should be called at least twice per second.
  45.    It can be called at a much higher rate without much loss. */
  46.  
  47. extern void ReturnVoid(void);
  48.   /* Allow the XFun to return false without generating an error message. */
  49.  
  50.  
  51. /* ------------- function parameter access ---------------- */
  52. /* Parameters are numbered from right to left starting at 0 */
  53.  
  54. extern short GetParmVal(long n,double *num);
  55.   /* Get the value of a simple numeric parameter.
  56.    Returns false if the value is an array or undefined */
  57.  
  58. extern void MakeParmExpr(long n,EXPR *xpr);
  59.   /* Make a parameter expression. (Used to access arrays).
  60.    The expression must be deallocated with FreeExpr(xpr). */
  61.  
  62. extern short GetParmName(long n,char **name);
  63.   /* Get a name parameter. (Used to get a filename or other string).
  64.     Returns false if the parameter was an expression or defined variable */
  65.  
  66.  
  67.  
  68. /* ------------------ global variable access ---------------- */
  69.  
  70. extern short GetVarVal(char *name,double *num);
  71.   /* Evaluate the named global variable.
  72.     Returns false if the value is an array or undefined */
  73.  
  74. extern void GetVarString(char *name,char **str);
  75.   /* Returns the string value of a named global variable.
  76.     Returns an empty string if unless the variable was set to a string */
  77.  
  78. extern void MakeVarExpr(char *name,EXPR *xpr);
  79.   /* Make a global variable expression. (Used to access arrays).
  80.    The expression must be deallocated with FreeExpr(xpr). */
  81.  
  82. extern short SetVarVal(char *name,double num);
  83.   /* Assign a single value to the named global variable.
  84.      Returns false if the variable is an illegal destination. */
  85.  
  86. extern short SetVarMatrix(char *name,double *arr,long rows,long cols);
  87.   /* Assign a 1D or 2D array to the named global variable. 
  88.      Returns false if the variable is an illegal destination.
  89.      The array must be allocated via NewPtr() and will be deallocated by MathPad. */
  90.  
  91. extern void FoldVar(char *name,long lim);
  92.   /* Add a dimension to the variable set by SetVarMatrix(). Can be called multiple
  93.      times to create more dimensions. */
  94.  
  95.  
  96.  
  97. /* ------------ general expression routines ----------------- */
  98.  
  99. extern short GetExprMatrix(EXPR xpr,double **mat,long *rows,long *cols);
  100.   /* Allocate memory and evaluate all elements of a 1D or 2D matrix expression into memory.
  101.    Returns a pointer to the matrix in mat.
  102.    A scalar will return cols=0 and rows=0. A 1D array will return cols=0.
  103.    An array with more than 2 dimensions will generate an error message and return false.
  104.    The matrix allocated by GetExprMatrix() should be deallocated with DisposPtr() */
  105.  
  106. extern short ProbeExpr(EXPR xpr,double *num,short *isarray,long *count);
  107.   /* Find out if an expression is a scalar or an array.
  108.    If scalar, returns true and sets num.
  109.    If array, returns false and sets isarray and count. A count of 0 means infinite array.
  110.    If the return value and isarray are both false the expression was undefined. */
  111.  
  112. extern void AddIndex(EXPR *xpr,double **iptr);
  113.   /* Add an index to allow evaluating individual array elements.
  114.    The double at iptr can be modified to index through the array.
  115.    To access a single element, an index must be added for each dimension of the array. */
  116.  
  117. extern void RemoveIndex(EXPR *xpr);
  118.   /* Can be used to remove the last index added by AddIndex(). Normally FreeExpr() is
  119.     be used to free the entire expression so this call is not required. */
  120.  
  121. extern short EvalExpr(EXPR xpr,double *num);
  122.   /* Evaluate an expression. Returns false if xpr is an array or undefined.*/   
  123.  
  124. extern void FreeExpr(EXPR xpr);
  125.   /* Free memory allocated to an expression.
  126.    Use to deallocate from MakeParmExpr() or MakeVarExpr() */
  127.  
  128.  
  129. /* ---------- PICT overlay ---------------- */
  130.  
  131. extern void SetPlotPICT(PicHandle thePic);
  132.   /* Allows an XFun to overlay PICT graphics on the plot. Overlay goes on current strip.
  133.    The XFun must allocate and create thePic. MathPad will dispose of it.  */
  134.  
  135. extern void SizePlotPICT(double left,double bot,double width,double ht);
  136.   /* Specify where to draw the PICT in data coordinates.
  137.     Default is to size the PICT to fill the data plot area.  */
  138.  
  139.  
  140. /* ---------- Document info ----------- */
  141.  
  142. short GetDocInfo(long *docref,FSSpec *fspec,WindowPtr *plotwindow);
  143.   /* Get info about the document being evaluated. Returns false if no open doc. */
  144.  
  145. extern void GetAngleUnits(double *unit);
  146.   /* Get the currently selected multiplier trig function parameters.
  147.      1.0 for radians, .017 for degrees */
  148.  
  149. extern void GetAxisRect(Rect *axisrect);
  150.   /* Get the current data axis rectangle in plot window coordinates */
  151.  
  152. extern void GetAxisLimits(double limits[6]);
  153.   /* Get the the current values of xmin,xmax,ymin,ymax,zmin,zmax */
  154.   
  155. extern void GetPlotInfo(double info[12]);
  156.   /* Get the the current values of xlo,xhi,ylo,yhi,zlo,zhi,
  157.      traceclick,xclick,yclick,zclick,ixclick,iyclick */
  158.  
  159.  
  160. /* --------------- Event handlers -------------*/
  161.  
  162. extern void InstallEventHandler(funptr handler);
  163.   /* install external event handler */
  164.   
  165. extern void SetCursorRegion(Cursor *curs,RgnHandle inside);
  166.   /* set region for mouse moved events */
  167.  
  168. extern void DoMenuItem(long selector);
  169.   /* Perform the action for a MathPad menu item. This allows the XFun event handler
  170.      intercept info from MenuSelect(theEvent->where) and pass back selections */
  171.  
  172.  
  173. /* -------------- Utillity --------------------*/
  174. extern short Sprintf(char *buf,char *fmt,double num);
  175.   /* Allows XFun some access to sprintf() without linking its own ANSI library */
  176.  
  177. extern void MapData(double x,double y,short *xpixel,short *ypixel);
  178.   /* use current plot window scaling to convert data coords to pixel coords */
  179.  
  180.  
  181.  
  182. /* -------------- CFun only -------------------*/
  183. extern void AddCFun(char *name,char *parms,funptr entry,funptr predef);
  184.   /* install external fun from code frag */
  185.  
  186. void AddLoopIndex(double **iptr);
  187.   /* Add global index to be used with subsequent EvalExpr() calls */
  188.   
  189. void RemoveLoopIndex(void);
  190.   /* Remove global index. Must be called to balance each AddLoopIndex() call */
  191.  
  192.  
  193. #ifdef __cplusplus
  194. }
  195. #endif
  196.